import React, { Fragment } from 'react';
import { Card, Descriptions, Button, Modal, notification } from 'antd';
import Zmage from 'react-zmage';
import { editStudents } from '@/services/api';

const Detail = ({ history }: any) => {
  const studentsData = JSON.parse(sessionStorage.getItem('studentsData') || '');
  let { extra = {} } = studentsData;
  if (extra === null) {
    extra = {};
  }

  const handleCheckCardId = () => {
    Modal.confirm({
      content: '确认验证身份证？',
      onOk: () => {
        console.log(studentsData);
        const newVal: any = {
          is_valid_card_id: 1,
        };

        const residence_images: any = [];
        const health_images: any = [];
        studentsData.residences.forEach((item: any) => {
          residence_images.push(item.id);
        });
        studentsData.healths.forEach((item: any) => {
          health_images.push(item.id);
        });
        newVal.residence_images = residence_images;
        newVal.health_images = health_images;
        delete studentsData.parent;
        delete studentsData.teacher;
        delete studentsData.clase;
        delete studentsData.image;
        delete studentsData.residences;
        delete studentsData.healths;
        editStudents({ ...studentsData, ...newVal }).then((resp: any) => {
          if (resp.status === 'success') {
            notification.success({ message: '验证身份证成功' });
            history.push('/applyManage/applyList');
          }
        });
      },
    });
  };

  const handleCancelCardId = () => {
    Modal.confirm({
      content: '确认撤销验证身份证？',
      onOk: () => {
        console.log(studentsData);
        const newVal: any = {
          is_valid_card_id: 0,
        };

        const residence_images: any = [];
        const health_images: any = [];
        studentsData.residences.forEach((item: any) => {
          residence_images.push(item.id);
        });
        studentsData.healths.forEach((item: any) => {
          health_images.push(item.id);
        });
        newVal.residence_images = residence_images;
        newVal.health_images = health_images;
        delete studentsData.parent;
        delete studentsData.teacher;
        delete studentsData.clase;
        delete studentsData.image;
        delete studentsData.residences;
        delete studentsData.healths;
        editStudents({ ...studentsData, ...newVal }).then((resp: any) => {
          if (resp.status === 'success') {
            notification.success({ message: '撤销验证身份证成功' });
            history.push('/applyManage/applyList');
          }
        });
      },
    });
  };

  return (
    <Fragment>
      <Card title="学生基本信息">
        <Descriptions>
          <Descriptions.Item label="姓名">{studentsData.name}</Descriptions.Item>
          <Descriptions.Item label="老师">
            {studentsData.teacher && studentsData.teacher.name}
          </Descriptions.Item>
          <Descriptions.Item label="就读班级和年级">
            {studentsData.clase && studentsData.clase.name}
          </Descriptions.Item>
          <Descriptions.Item label="家长">
            {studentsData.parent && studentsData.parent.name}
          </Descriptions.Item>
          <Descriptions.Item label="身份证"> {studentsData.card_id}</Descriptions.Item>
          {/* <Descriptions.Item label="出生日期"> {studentsData.birth_day}</Descriptions.Item> */}
          <Descriptions.Item label="老师是否认领">
            {studentsData.status ? '已认领' : '未认领'}
          </Descriptions.Item>
          <Descriptions.Item label="是否交学费">
            {studentsData.is_paid ? '已缴费' : '未缴费'}
          </Descriptions.Item>
          <Descriptions.Item label="学费"> {studentsData.money / 100}</Descriptions.Item>
          <Descriptions.Item label="是否进班">
            {studentsData.is_arranged ? '已进班' : '未进班'}
          </Descriptions.Item>
          <Descriptions.Item label="是否验证身份证号">
            {studentsData.is_valid_card_id ? (
              <span>
                已验证&nbsp;&nbsp;
                <Button type="primary" size="small" onClick={handleCancelCardId}>
                  撤销
                </Button>
              </span>
            ) : (
              <span>
                未验证&nbsp;&nbsp;
                <Button type="primary" size="small" onClick={handleCheckCardId}>
                  验证
                </Button>
              </span>
            )}
          </Descriptions.Item>
          <Descriptions.Item label="民族">{studentsData.national}</Descriptions.Item>
        </Descriptions>
      </Card>
      <Card title="学生其他信息" className="pageCard">
        <Descriptions bordered>
          <Descriptions.Item label="入学时间">
            {extra.admission_at}
            {extra.address}
          </Descriptions.Item>
          <Descriptions.Item label="联系电话">{extra.tel}</Descriptions.Item>
          <Descriptions.Item label="家庭住址">{extra.address}</Descriptions.Item>
          <Descriptions.Item label="户籍所在乡镇">{extra.town}</Descriptions.Item>
          {/* <Descriptions.Item label="是否属县外户籍">
            {extra.is_household ? '是' : '否'}
          </Descriptions.Item>
          <Descriptions.Item label="所属村(街道办)">{extra.village}</Descriptions.Item>
          <Descriptions.Item label="组(门牌号)">{extra.groups}</Descriptions.Item> */}
          <Descriptions.Item label="户口性质">{extra.register_type}</Descriptions.Item>
          <Descriptions.Item label="是否残疾">
            {extra.is_disability ? '是' : '否'}
          </Descriptions.Item>
          {/* <Descriptions.Item label="残疾类型">
            {extra.disability_type ? '是' : '否'}
          </Descriptions.Item>
          <Descriptions.Item label="残疾等级">{extra.disability_level}</Descriptions.Item>
          <Descriptions.Item label="是否三类残疾">
            {extra.is_three_type_disability ? '是' : '否'}
          </Descriptions.Item>
          <Descriptions.Item label="就读方式(残疾)">{extra.study_way}</Descriptions.Item>
          <Descriptions.Item label="是否参加体检">
            {extra.is_medical ? '是' : '否'}
          </Descriptions.Item>
          <Descriptions.Item label="上学年是否参加体质健康监测">
            {extra.is_last_year_medical ? '是' : '否'}
          </Descriptions.Item> */}
          <Descriptions.Item label="是否转校生">
            {extra.is_transfer ? '是' : '否'}
          </Descriptions.Item>
          <Descriptions.Item label="是否转班生">
            {extra.is_clase_transfer ? '是' : '否'}
          </Descriptions.Item>
          {extra.is_clase_transfer && (
            <>
              <Descriptions.Item label="转出班级">
                {extra.in_clase && extra.in_clase.name}
              </Descriptions.Item>
              <Descriptions.Item label="转入班级">
                {extra.out_clase && extra.out_clase.name}
              </Descriptions.Item>
            </>
          )}
          {/* <Descriptions.Item label="是否受过学前教育">
            {extra.is_pre_edu ? '是' : '否'}
          </Descriptions.Item>
          <Descriptions.Item label="是否寄宿生">{extra.is_boarder ? '是' : '否'}</Descriptions.Item> */}
          <Descriptions.Item label="是否自主搬迁人员子女">
            {extra.is_moving ? '是' : '否'}
          </Descriptions.Item>
          <Descriptions.Item label="是否进城务工人员子女">
            {extra.is_city_moving ? '是' : '否'}
          </Descriptions.Item>
          {/* <Descriptions.Item label="是否留守儿童">{extra.is_left ? '是' : '否'}</Descriptions.Item>
          <Descriptions.Item label="学生来源">{extra.come_from}</Descriptions.Item>
          <Descriptions.Item label="政治面貌">{extra.politics_status}</Descriptions.Item>
          <Descriptions.Item label="是否港澳台">
            {extra.is_hk_macao_taiwan ? '是' : '否'}
          </Descriptions.Item> */}
          <Descriptions.Item label="是否异地移民搬迁子女">
            {extra.is_foreign ? '是' : '否'}
          </Descriptions.Item>
          {/* <Descriptions.Item label="是否单亲">
            {extra.is_single_parent ? '是' : '否'}
          </Descriptions.Item>
          <Descriptions.Item label="是否孤儿">{extra.is_orphan ? '是' : '否'}</Descriptions.Item> */}
          <Descriptions.Item label="是否建档立卡贫困户">
            {extra.is_poverty ? '是' : '否'}
          </Descriptions.Item>
          <Descriptions.Item label="是否低保户">
            {extra.is_allowance ? '是' : '否'}
          </Descriptions.Item>
          {/* <Descriptions.Item label="是否五保户">{extra.is_infirm ? '是' : '否'}</Descriptions.Item>
          <Descriptions.Item label="是否重病重残儿童">
            {extra.is_severe ? '是' : '否'}
          </Descriptions.Item>
          <Descriptions.Item label="是否服刑人员家庭">
            {extra.is_family_prisoner ? '是' : '否'}
          </Descriptions.Item> */}
          <Descriptions.Item label="监护人">{extra.guardian}</Descriptions.Item>
          <Descriptions.Item label="监护关系">{extra.guardianship}</Descriptions.Item>
        </Descriptions>
      </Card>
      <Card title="退学信息" className="pageCard">
        <Descriptions>
          <Descriptions.Item label="是否退学">{extra.is_out ? '是' : '否'}</Descriptions.Item>
          <Descriptions.Item label="退学原因">{extra.out_reason}</Descriptions.Item>
        </Descriptions>
      </Card>
      <Card title="学生照片" className="pageCard">
        {studentsData.image && <Zmage src={studentsData.image.url} style={{ width: 400 }} />}
      </Card>
      <Card title="户口簿照片" className="pageCard">
        {studentsData.residences.length
          ? studentsData.residences.map((item: any) => (
              <Zmage style={{ width: 400 }} src={item.url} key={item.id} />
            ))
          : null}
      </Card>
      <Card title="健康照片" className="pageCard">
        {studentsData.healths.length
          ? studentsData.healths.map((item: any) => (
              <Zmage style={{ width: 400 }} src={item.url} key={item.id} />
            ))
          : null}
      </Card>
    </Fragment>
  );
};

export default Detail;
